//
//  KRLGradientButton.m
//  KaraLive
//
//  Created by Zhijia Zhong on 2018/9/12.
//  Copyright © 2018年 naxigoren. All rights reserved.
//

#import "KRLGradientButton.h"

@implementation KRLGradientButton

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self.layer insertSublayer:[self gradientLayer] atIndex:0];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self.layer insertSublayer:[self gradientLayer] atIndex:0];
    }
    return self;
}

- (CAGradientLayer *)gradientLayer {
    // 添加渐变layer到登录按钮最底层，避免遮住title
    CAGradientLayer *subLayer = [CAGradientLayer layer];
    subLayer.frame = self.bounds;
    
    // 使用渐变色
    subLayer.colors = @[(__bridge id)[UIColor colorWithRGB:0xff6c6c].CGColor,
                        (__bridge id)[UIColor colorWithRGB:0xff9451].CGColor];
    // 开始点
    subLayer.startPoint = CGPointMake(0, 0);
    // 结束点
    subLayer.endPoint = CGPointMake(1, 1);
    
    // 使用圆角
    subLayer.cornerRadius = self.height / 2;
    
    // 使用阴影
    subLayer.shadowColor = [UIColor colorWithRGB:0xff865b].CGColor;
    subLayer.shadowOffset = CGSizeMake(0, 3);
    subLayer.shadowOpacity = 0.6;
    return subLayer;
}

@end
